package com.maptool.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.maptool.R;
import com.maptool.config.MapConfig;
import com.maptool.pojo.ClipPojo;

import java.util.List;

public class ClipGeometryAdapter extends ArrayAdapter<ClipPojo> {


    public ClipGeometryAdapter(@NonNull Context context, List<ClipPojo> items) {
        super(context, 0, items);
    }


    @SuppressLint("SetTextI18n")
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.clip_card_layout, parent, false);
        }

        ClipPojo item = getItem(position);

        TextView clip = convertView.findViewById(R.id.clip);
        Button look = convertView.findViewById(R.id.look);
        Button saveClip = convertView.findViewById(R.id.saveClip);
        int i = +position + 1;
        clip.setText(MapConfig.clipName + "-" + i);
        saveClip.setOnClickListener(v -> {
            saveClip(item);
        });


        look.setOnClickListener(v -> {
            lookApi(item);
        });

        return convertView;

    }

    private void lookApi(ClipPojo item) {
        lookApi.lookFun(item);
    }

    private void saveClip(ClipPojo item) {
        saveApi.saveFun(item);
    }


    public LookApi lookApi;//查看
    public SaveApi saveApi;//保存

    public void setLookApi(LookApi lookApi) {
        this.lookApi = lookApi;
    }

    public void setSaveApi(SaveApi saveApi) {
        this.saveApi = saveApi;
    }

    public interface LookApi {
        void lookFun(ClipPojo clipPojo);
    }

    public interface SaveApi {
        void saveFun(ClipPojo clipPojo);
    }
}
